// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import Client from '@api/user/api/SysRegionTagApi'

import ComClass from '@api/ComQuery'
import ListClass from '@api/user/model/SysRegionDto'

const CLIENT = CORE.grpcCLIENT(Client)
const COM = [ComClass, 'comQuery']

// ============================== 导出远程接口 ============================== //

export default {
  // —————————————————————————————— 列表 —————————————————————————————— //

  async getList(param, TIP = '查询列表') {
    const DTO = CORE.grpcDTO(ListClass, param, COM)
    const resp = await CORE.grpc(TIP, CLIENT, 'querySysRegionTagList', DTO)
    return [resp.comQuery.totalCount, resp.content || []]
  },
  transList(arr, { state: { DICT } }) {
    return arr.map((item) => {
      DICT.TYPE.forEach(([type]) => {
        const dict = DICT[type.toUpperCase()] || []
        item[type] = {
          img: item.qrCodeUrl,
          dataList: dict.map(([word, key]) => [word, item[key]]),
        }
      })
      return item
    })
  },
}
